<template>
    <el-drawer :title="title" v-model="showDrawer" direction="rtl" size="40%" :before-close="close"
        :close-on-press-escape="false">
        <div class="pug-drawer">
            <div class="body">
                <slot></slot>
            </div>
            <div class="btns">
                <el-button type="primary" size="default" :loading="loading" class="mr-5" @click="submit">提交</el-button>
                <el-button type="default" size="default" @click="close">取消</el-button>
            </div>
        </div>
    </el-drawer>
</template>

<script setup>

import { ref } from 'vue'
import { confirm } from '@/utils/utils'
const loading = ref(false)
const showDrawer = ref(false);

defineProps({
    title: {
        type: String,
        default: "修改密码"
    }
})


const open = () => {
    showDrawer.value = true;
}

const close = () => {
    confirm('你确定要离开吗？').then(() => {
        showDrawer.value = false;
    }).catch(() => {
        showDrawer.value = true;
    })
}

const showLoading = () => loading.value = true
const hideLoading = () => loading.value = false

// 向父组件暴露当前组件的事件和行为，在父组件中通过子组件定义的ref调用
defineExpose({
    open,
    close,
    showLoading,
    hideLoading
})


const emit = defineEmits(["submit"])
const submit = () => emit("submit")

</script>

<style>
.pug-drawer {
    width: 100%;
    height: 100%;
    position: relative;
    @apply flex flex-col;
}

.el-drawer__header {
    background: #fafafa;
    padding-bottom: 10px;
}

.pug-drawer .body {
    flex: 1;
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    bottom: 50px;
    overflow-y: auto;
}

.pug-drawer .btns {
    height: 50px;
    @apply flex items-center mt-auto;
}
</style>

